﻿// Spun AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using Spun.Controllers;

namespace Spun.Communications
{
    using Views;
    using Hosting;

    public class Start
    {
        public const string DEFAULT_VIEW_NAME = "Main.view";

        public void Spun<BC>(string VirtualDirectory, string BaseControllerName)
            where BC : IController, new()
        {
            Spun<BC>(Host.HOST_WILDCARD, 80, VirtualDirectory, BaseControllerName, DEFAULT_VIEW_NAME);
        }

        public void Spun<BC>(string Host, short Port, string VirtualDirectory, string BaseControllerName)
            where BC : IController, new()
        {
            Spun<BC>(Host, Port, VirtualDirectory, BaseControllerName, DEFAULT_VIEW_NAME);
        }

        public void Spun<BC>(
            string Host,
            short Port,
            string VirtualDirectory,
            string BaseControllerName,
            string DefaultViewName
            )
            where BC : IController, new()
        {
            var AppCtxFactory = new ApplicationContextFactory<BC>(BaseControllerName);
            Terminal = new Terminal(Host, Port, VirtualDirectory, AppCtxFactory, new ViewServer(DefaultViewName));
        }

        private Terminal Terminal;

        static Start()
        {
            SpunJson.EnableJsonForSpun();
        }
    }
}
